﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebLibSolPedBE;

namespace WebApplication1
{
    public partial class formPedidoCompraDetalle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CargarDatosCabecera();
            }
        }

        private void CargarDatosCabecera(){
            if (Session["objPedCom"] != null)
            {
                PedidoCompraCabBE objPedCab = (PedidoCompraCabBE)Session["objPedCom"];
                lblPedCom.Text = objPedCab.PO_NUMBER;
                lblFecha.Text = objPedCab.DOC_DATE;
                lblProveedor.Text = objPedCab.VALOR1.Trim();
                lblMonto.Text = objPedCab.TARGET_VAL;
                lblUsuario.Text = objPedCab.CREATED_BY;

                CargarLista(objPedCab.PO_NUMBER, objPedCab.FRGGR);
            }
            
        }

        private void CargarLista(string po_number, string cod_lib)
        {
            List<PedidoCompraDetBE> lst = LibSolPedDALF.DaoFactory.LiberaPedidoCompraF.getLstPedidoCompraDet(po_number, cod_lib);
            gvGrid.DataSource = lst;
            gvGrid.DataBind();
        }

        protected void gvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the control
                var lblPosicionDescripcion = (Label)e.Row.FindControl("lblPosicionDescripcion");
                var lblUnidadCantidad = (Label)e.Row.FindControl("lblUnidadCantidad");
                var lblPrecioValor1Plant = (Label)e.Row.FindControl("lblPrecioValor1Plant");
                var lblCeCo = (Label)e.Row.FindControl("lblCeCo");
                var lblOrden = (Label)e.Row.FindControl("lblOrden");
                var lblCtaCon = (Label)e.Row.FindControl("lblCtaCon");
                //Display the data
                var data = e.Row.DataItem;
                PedidoCompraDetBE it = (PedidoCompraDetBE)data;
                lblPosicionDescripcion.Text = it.PO_ITEM + "-" + it.SHORT_TEXT;
                lblUnidadCantidad.Text = it.UNIT + " - " + it.DISP_QUAN;
                lblPrecioValor1Plant.Text = it.NET_PRICE + " " + it.VALOR1.Trim() + " - " + it.PLANT;
                lblCeCo.Text = it.VALOR2.Trim();
                lblOrden.Text = it.VALOR3.Trim();
                lblCtaCon.Text = it.VALOR4.Trim();
            }
        }
    }
}